/* eslint-disable prettier/prettier */
import React, { Component } from "react";
import { Button, Checkbox, Input, Spin, message,InputNumber } from "antd";
import { messages } from "share/common";
import HotelServer from "../hotel-server";

const {TextArea} = Input;
class SetView extends Component {
  constructor(props) {
    super(props);
    this.state = {
      loading: false,
      hotelData: {}, // 酒店基础设置数据
      isOpen: false, // 是否启用
      text: "", // 显示的页尾文案
    };
  }

  componentWillMount() {
    this.initData();
  }

  initData = () => {
    HotelServer(this)
      .getPlatformModelData({ companyOid: this.props.companyOID })
      .then((res) => {
        this.setState({
          hotelData: res.data.body,
          isOpen: res.data.body.isTravelRuleShowed || false,
          text: res.data.body.pageFootText || "",
          isReserveTipOpen: res.data.body.isContinuousBooking || false,
          bookingDaysLimit:res.data.body.bookingDaysLimit || 10,
          bookingLimitDesc:res.data.body.bookingLimitDesc || "",
        });
      });
  };

  onIsOpen = (eve) => {
    this.setState({ isOpen: eve.target.checked });
  };

  onReserveTipOpen = (eve) => {
    this.setState({ isReserveTipOpen: eve.target.checked });
  };

  onTextChange = (eve) => {
    this.setState({ text: eve.target.value });
  };

  onSaveSetting = () => {
    const { hotelData, text, isOpen, isReserveTipOpen,bookingDaysLimit,bookingLimitDesc } = this.state;
    const params = Object.assign({}, hotelData);
    params.pageFootText = text;
    params.companyOid = this.props.companyOID;
    params.isTravelRuleShowed = isOpen;
    params.isContinuousBooking = isReserveTipOpen;
    params.bookingDaysLimit = bookingDaysLimit;
    params.bookingLimitDesc = bookingLimitDesc;
    HotelServer(this)
      .savePlatformModelData(params)
      .then((res) => {
        if (res.data.success) {
          message.success(messages("supplier-1.key355") /*保存成功*/);
          this.initData();
        } else {
          message.error(res.data.message);
        }
      });
  };

  render() {
    const { loading, isOpen, text, isReserveTipOpen,bookingLimitDesc,bookingDaysLimit } = this.state;
    return (
      <div className="airline-config-container">
        <Spin spinning={loading}>
          <h2>{messages('supplier-1.key773')/*连续预定提示*/}</h2>
          <a className="a-line-bottom">{messages('supplier-1.key774')/*可根据酒店资源，对员工预定进行个性化提示*/}</a>
          <Checkbox checked={isReserveTipOpen} onChange={this.onReserveTipOpen}>
            {messages("supplier-1.key35") /*启用temp*/}
          </Checkbox>
          {
            isReserveTipOpen && <div>
              <div>{messages('supplier-1.key775')/*当选择天数超过*/}<InputNumber min={0} value={bookingDaysLimit} onChange={value => this.setState({ bookingDaysLimit: value })} />{messages('supplier-1.key834',{arg1: bookingDaysLimit})/*天时（离店-入住<{arg1}）进行提示*/}</div>
              <div style={{ marginTop: "12px" }}>
                <span>{messages('supplier-1.key777')/*提示文案：*/}</span>
                <TextArea
                  style={{marginTop:"6px"}}
                  value={bookingLimitDesc}
                  placeholder={messages('supplier-1.key833')/*eg：因酒店资源限制，预订天数请尽量少于10天*/}
                  onChange={eve => this.setState({ bookingLimitDesc: eve.target.value })}
                />
              </div>
            </div>
          }
          <br/>
          <br />
          <h2>{messages("supplier-1.key514") /*首页显示我的行程模块*/}</h2>
          <a className="a-line-bottom">
            {messages("supplier-1.key515") /*启用后，可在首页显示最近审批通过的差旅申请单*/}
          </a>
          <Checkbox checked={isOpen} onChange={this.onIsOpen}>
            {messages("supplier-1.key35") /*启用temp*/}
          </Checkbox>
          <br />
          <br />
          <h2>{messages("supplier-1.key399") /*页尾文案*/}</h2>
          <a className="a-line-bottom">{messages("supplier-1.key400") /*可自行配置页面底部文案*/}</a>
          <Input
            value={text}
            onChange={this.onTextChange}
            placeholder={messages("supplier-1.key103") /*请输入temp2*/}
          />
          <br />
          <br />
          <br />
          <br />
          <Button type="primary" onClick={this.onSaveSetting}>
            {messages("supplier-1.key356") /*保存配置*/}
          </Button>
        </Spin>
      </div>
    );
  }
}

export default SetView;
